<template>
  <div>
    <el-dialog
      v-model="props.logTableVisible"
      title="发布记录"
      @close="handleLogClose"
    >
      <el-table :data="dataList" height="450">
        <el-table-column prop="version" label="版本" width="80" align="center" />
        <el-table-column prop="status" label="发布状态" align="center" />
        <el-table-column
          prop="newTime"
          label="发布时间"
          width="200"
          align="center"
        />
        <el-table-column prop="userId" label="发布人" align="center" />
        <el-table-column label="操作" width="200" align="center">
          <template #default="scope">
            <el-button link type="primary" @click="handleBtn(scope.row, 1)"
              >发布配置</el-button
            >
            <el-button link type="primary" @click="handleBtn(scope.row, 0)"
              >发布日志</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <Pagination
        :total="total"
        :limit="searchFrom.pageSize"
        :page="searchFrom.pageNum"
        @pagination="handleCurrentChange"
      ></Pagination>
      <ReleaseDrawer
       :assemble="true"
        :isRelease="isRelease"
        :publicFrom="publicItem"
        :releaseVisible="releaseVisible"
        @handleClose="handleReleaseClose"
        @handleSure="handleReleaseSure"
      ></ReleaseDrawer>
    </el-dialog>
  </div>
</template>
<script setup>
import { ref, defineProps, defineEmits, onMounted, watch } from "vue";
import ReleaseDrawer from "./releaseDrawer.vue";
import { useRouter } from "vue-router";
const emits = defineEmits(["handleLogClose"]);
const { proxy } = getCurrentInstance();
const router = useRouter();
const props = defineProps({
  logTableVisible: {
    type: Boolean,
    default: false,
  },
  // 传值数据对象
  publicFrom: {
    type: Object,
    default: {},
  },
});
const searchFrom = ref({
  pageNum: 1,
  pageSize: 10,
  param: {
    websiteId: null,
  },
});
const dataList = ref([]);
const total = ref(0);
const publicItem = ref({});
const releaseVisible = ref(false);
const isRelease = ref(true);
watch(
  () => props.logTableVisible,
  () => {
    if (!props.logTableVisible) return;
    getList();
  }
);
const getList = () => {
  searchFrom.value.param.websiteId = props.publicFrom.id;
  site.general
    .websitepublishrecordList({
      data: searchFrom.value,
    })
    .then((res) => {
      total.value = res.total;
      if (res.data?.length) {
        res.data = res.data.map((code) => {
          return {
            ...code,
            newTime:  proxy.DateTime(code.created) ,
          };
        });
      }
      dataList.value = res.data;
    });
};
const handleBtn = (row, index) => {
  publicItem.value = row;
  if (index) {
    router.push({ path: `sitePublish/publishSite`, query: { id: row.websiteId } });
  } else {
    releaseVisible.value = true;
    isRelease.value = false;
  }
};

const handleLogClose = () => {
  emits("handleLogClose");
};
// 分页
const handleCurrentChange = (newPage) => {
  searchFrom.value.pageNum = newPage.page;
  searchFrom.value.pageSize = newPage.limit;
  getList();
};
const handleReleaseClose = () => {
  releaseVisible.value = false;
};
const handleReleaseSure = () => {
  releaseVisible.value = false;
  getList();
};
</script>